package com.woniuxy.enjoylife.controller;


import com.woniuxy.enjoylife.entity.Goods_comment;
import com.woniuxy.enjoylife.entity.Goods_comment_reply;
import com.woniuxy.enjoylife.entity.dto.ReturnGoodsCommentReplyDto;
import com.woniuxy.enjoylife.entity.dto.SelectGoodsCommentDto;
import com.woniuxy.enjoylife.service.Goods_commentService;
import com.woniuxy.enjoylife.service.Goods_comment_replyService;
import com.woniuxy.enjoylife.utils.PageResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author teamEnjoyLife75
 * @since 2021-01-23
 */
@RestController
@RequestMapping("/goodsComment")
public class Goods_commentController {
    @Resource
    private Goods_commentService goodsCommentService;
    @Resource
    private Goods_comment_replyService goodsCommentReplyService;
    @Resource
    private HttpServletRequest request;

    @RequestMapping("/insertGoodsComment")
    public boolean insertGoodsComment(@RequestBody Goods_comment goodsComment) {
        goodsComment.setUid((int) request.getSession().getAttribute("id"));
        goodsComment.setTime(LocalDateTime.now());
        return goodsCommentService.save(goodsComment);
    }

    @RequestMapping("/deleteGoodsComment")
    public boolean deleteGoodsComment(Goods_comment goodsComment) {
        goodsComment.setUid((int) request.getSession().getAttribute("id"));
        return goodsCommentService.delete(goodsComment);
    }


    @RequestMapping("/selectGoodsCommentsDto")
    public List<ReturnGoodsCommentReplyDto> selectGoodsCommentsDto(Goods_comment goodsComment) {
        goodsComment.setUid((int) request.getSession().getAttribute("id"));
        return goodsCommentService.selectGoodsCommentsDto(goodsComment);
    }

    @RequestMapping("/insertGoodsCommentRep")
    public boolean insertGoodsCommentRep(@RequestBody Goods_comment_reply goodsCommentReply){
        goodsCommentReply.setTime(LocalDateTime.now());
        return goodsCommentReplyService.save(goodsCommentReply);
    }

    @RequestMapping("/selectGoodsComments")
    public PageResult<ReturnGoodsCommentReplyDto> selectGoodsComments(SelectGoodsCommentDto dto){
        return goodsCommentService.selectGoodsComments(dto);
    }


}

